package demo.demo02;

public class While {
    public static void main(String[] args) {
        //打印0-100的总和以及奇数和and偶数和
        int sum = 0;
        int i = 1;
        int jishu = 0;
        int oushu = 0;
        while (i <= 100) {
            sum += i;
            if (i % 2 == 1) {
                jishu += i;
            } else {
                oushu += i;
            }
            i++;
        }
        System.out.println("1-100的总和：" + sum);
        System.out.println("1-100的奇数和：" + jishu);
        System.out.println("1-100的偶数和：" + oushu);
        System.out.println("======================");

        //打印一百以内的数，每行5个数
        int a = 0;
        while (a < 100) {
            a++;
            System.out.print(a + "\t");
            if (a % 5 == 0) {
                System.out.println();
            }
        }
        System.out.println("======================");
        int m = 0;
        System.out.println("Begin");
        while (true) {
            m++;
            int n = (int) Math.round(1000 * Math.random());//Math.round四舍五入
            if (n == 520) {
                break;
            }
            System.out.print(n + "\t");
            if (m % 10 == 0) {
                System.out.println();
            }
        }
        System.out.println("\nOver！！！" + m + "次");
    }
}
